<?php
namespace Android\Controller;

class AppinitController extends BaseController {


    /**
     * 客户端初始化接口
     *
     *
     *
     */
    public function init() {
        $week = getTimeInfo($this->term['stime'],$this->term['etime'],true);
        $week === false && $week = 0;
        $value = array(
            'week' => $week,
            'about' => 'http://www.e8net.cn/dianm/android.php/About',
        );

        $this->out($this->success,'Success',$value);
    }


    /**
     *  App版本更新接口
     *
     */
    public function update() {

        $is_current = 1;

        $clientVersion = I ('request.version_string');
        if (empty($clientVersion)) $this->out($this->fail,'请传入一个版本号');

        $Version = M ('Version');
        $serverVersionObj = $Version->order('version_string desc, addtime desc')->find();
        if (empty($serverVersionObj)) $this->out($this->fail,'服务器没有版本信息');

        $updateSwitch = (int) D('Appconfig')->get('update_switch');

        if ( $updateSwitch !== 0 )
            if ($clientVersion !== $serverVersionObj['version_string'] && $clientVersion < $serverVersionObj['version_string'])
                $is_current = 0;


        $data = array(
            'is_current' => $is_current,
            'update_force' => (int)$serverVersionObj['update_force'],
            'server_url' => $serverVersionObj['server_url'],
            'download_url' => $serverVersionObj['download_url'],
            'version_string' => $serverVersionObj['version_string'],
            'remark' => $serverVersionObj['remark']
        );

        $this->out($this->success,'',$data);

    }



}